<template>
  <div class="switch-company">
    <el-switch :value="row.autoBalance"
               :active-value="true"
               :inactive-value="false"
               @change="handleSwitch">
    </el-switch>
  </div>
</template>

<script>
import { carrier, customer } from "@/api/index";

export default {
  name: "SwitchEntrustBill",
  inject: ["$table"],
  props: {
    row: {
      type: Object,
      default: () => { }
    }
  },
  methods: {
    handleSwitch () {
      console.log("========", this.row, this.row.autoBalance)
      this.$confirm(
        `是否确认${this.row.autoBalance ? `关闭` : `开启`}委托对账？`,
        "提示"
      )
        .then(async () => {
          let response = this.row.carrierId ? await carrier[this.row.autoBalance ? 'closeAutoBalance' : 'openAutoBalance']({ carrierId: this.row.carrierId }) : await customer[this.row.autoBalance ? 'closeAutoBalance' : 'openAutoBalance']({ customerId: this.row.customerId });
          this.$nextTick(() => {
            this.$message.success(response.message);
            // 刷列表 
            this.$table.search();
          });
        })
        .catch((err) => {
          console.log("err", err);
        });
    }
  }
};
</script>

<style lang="scss" scoped>
/deep/.el-switch.is-checked .el-switch__core {
  border-color: #13ce66;
  background-color: #13ce66;
}
</style>
